package com.yc.commontlib.test

import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.annotation.MainThread
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelLazy
import androidx.lifecycle.ViewModelProvider
import com.yc.commontlib.base.YcBaseViewModel
import kotlinx.coroutines.GlobalScope
import java.io.Serializable
import java.lang.reflect.ParameterizedType

/**
 * Creator: yc
 * Date: 2021/6/9 16:27
 * UseDes:
 */
fun main() {
    val data: ArrayList<TestData> = object : ArrayList<TestData>() {}
    val data2: ArrayList<TestData> = ArrayList()
    println("--${Test2.filter(data2)}--")
    funTestCall(object :TestCall{
        override fun call() {
        }
    })
    funTestCall2 { }
}
fun funTestCall(call:TestCall){

}
fun funTestCall2(call:TestCall2){

}
interface TestCall{
    fun call()
}
fun interface TestCall2{
    fun call2()
}
class TestData : Serializable {

}


class ac :AppCompatActivity(){
    val vm : YcBaseViewModel by viewModels()
}
object Test2 {
    inline fun <reified T> filter(list: ArrayList<T>): Boolean {
        val parameterizedType = list.javaClass.genericSuperclass as ParameterizedType
        val tClass = parameterizedType.actualTypeArguments[0]
        val tClass2 = tClass as Class<*>
        return tClass2.isAssignableFrom(Serializable::class.java)
    }

    inline fun <reified T> test(value: T): Boolean {
        if (value is ArrayList<*>) {
            val parameterizedType = value.javaClass.genericSuperclass as ParameterizedType
            val tClass = parameterizedType.actualTypeArguments[0]
            val tClass2 = tClass as Class<*>
            return tClass2.isAssignableFrom(Serializable::class.java)
        }
        return false
    }
}